package com.bdqn.mapper.impl;

import com.bdqn.mapper.RoleMapper;
import com.bdqn.pojo.Role;
import com.bdqn.pojo.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("roleMapper")
public class RoleServiceImpl implements RoleMapper {
    @Autowired
    private RoleMapper roleMapper;

    /**
     * 根据角色名称添加信息
     *
     * @param role
     * @return
     */
    @Override
    public int add(Role role) {
        try {
            return roleMapper.add(role);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 查询角色所有信息
     *
     * @param roleName
     * @return
     */
    @Override
    public List<Supplier> selectRoleList(String roleName) {
        try {
            return roleMapper.selectRoleList(roleName);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int delRoleId(Integer id) {
        try {
            return roleMapper.delRoleId(id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int updateRole(Role role) {
        try {
            return roleMapper.updateRole(role);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    public RoleMapper getRoleMapper() {
        return roleMapper;
    }

    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }
}
